package com.bestcem.xm.label.grpc.service.param.label;

import com.bestcem.xm.label.entity.pojo.LabelDO;
import lombok.Getter;
import lombok.Setter;

import javax.validation.Valid;
import javax.validation.constraints.Size;
import java.util.List;
import java.util.Objects;

/**
 * 创建标签 参数校验
 *
 * @author yf.wang <yf.wang@idiaoyan.com>
 * @version V1.0
 * @date 2021/5/21
 */
@Getter
@Setter
public class CreateLabelParam extends LabelParamBase {
    /**
     * 标签值
     */
    @Valid
    @Size(min = 1, max = 30, message = "标签值最少1个 最多30个")
    private List<CreateLabelValueParam> values;


    /**
     * CreateLabelParam -> LabelDO
     *
     * @param param CreateLabelParam
     * @return LabelDO
     */
    public static LabelDO convert(CreateLabelParam param) {
        LabelDO label = new LabelDO();

        if (Objects.isNull(param)) {
            return label;
        }

        label.setLabelGroupId(param.getLabelGroupId());
        label.setOrgId(param.getOrgId());
        label.setName(param.getName());

        if (Objects.nonNull(param.getAuto())) {
            label.setAuto(param.getAuto() ? 1 : 0);
        }
        if (Objects.nonNull(param.getManual())) {
            label.setManual(param.getManual() ? 1 : 0);
        }

        return label;
    }

}
